package cn.com.dcsgo;

import java.util.Arrays;
import java.util.Scanner;

/**
 * Main
 *
 * @author Dcsgo
 * @since 2025/2/17 15:05
 */

public class Main {
    private static final Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        groupsTest();
    }

    /**
     * 多组测试练习
     */
    public static void groupsTest() {
        System.out.println("请输入组数：");
        int groupNumber = scanner.nextInt();
        System.out.println("请输入每组的音节个数：");
        int syllableNumber = scanner.nextInt();
        int[][] groups = new int[groupNumber][];
        boolean[] isErrorGroups = new boolean[groupNumber];
        String[][] inputs = new String[groupNumber][syllableNumber];
        Syllable[][] syllables = new Syllable[groupNumber][syllableNumber];
        boolean isAllRight = true;
        //生成groupNumber组随机音节并读取用户每组的输入
        for (int i = 0; i < groupNumber; i++) {
            groups[i] = RandomSyllableNumberMaker.getRandomSyllableNumber(syllableNumber);
            System.out.println(Arrays.toString(groups[i]));
            System.out.println("请输入与之对应的唱名：");
            for (int j = 0; j < syllableNumber; j++) {
                inputs[i][j] = scanner.next();
                syllables[i][j] = new Syllable(groups[i][j]);
            }

            //判断用户输入的是否正确
            for (int j = 0; j < syllableNumber; j++) {
                if (!syllables[i][j].getName().equals(inputs[i][j])) {
                    isErrorGroups[i] = true;
                    isAllRight = false;
                    break;
                }
            }
        }

        if (isAllRight) {
            System.out.println("恭喜您，全部正确！");
            return;
        }

        //错误结果输出
        System.out.println("错误组如下：");
        for (int i = 0; i < groupNumber; i++) {
            if (isErrorGroups[i]) {
                System.out.println(Arrays.toString(groups[i]));
                System.out.println("预期：" + Arrays.toString(syllables[i]));
                System.out.println("实际：" + Arrays.toString(inputs[i]));
                System.out.println();
            }
        }
    }
}
